//
//  YLQualificationSureView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/12/27.
//  Copyright © 2017年 she1323. All rights reserved.
//  资格确认

#import "YLQualificationSureView.h"
#import <Masonry.h>
#import "YLGlobeHeader.h"
#import "YLAccountTool.h"
#import "WHNetworkTool.h"
@implementation YLQualificationSureView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}



- (void)setUpUI
{
    self.backgroundColor =YLColorA(0, 0, 0, 0.4);
    
    UITapGestureRecognizer *tapDismiss = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeFromSuperview)];
    [self addGestureRecognizer:tapDismiss];
    
    __weak typeof(self) weakSelf = self;
    UIView *baseView = [[UIView alloc] init];
    [self addSubview:baseView];
    [baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf);
        make.left.mas_equalTo(weakSelf).mas_offset(30);
        make.right.mas_equalTo(weakSelf).mas_offset(-30);
    }];
    baseView.backgroundColor = [UIColor whiteColor];
    baseView.layer.masksToBounds = YES;
    baseView.layer.cornerRadius = 8.0;
    baseView.layer.borderWidth = 0.5f;
    baseView.layer.borderColor = YLLOrgColor.CGColor;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = YLLOrgColor;
    titleLabel.font = [UIFont boldSystemFontOfSize:25];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"合格投资者确认";
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(baseView);
        make.top.mas_equalTo(baseView).mas_offset(40);
    }];
    
    
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.numberOfLines = 0;
    contentLabel.textColor = YLColor(70, 70, 70);
    contentLabel.font = [UIFont systemFontOfSize:16.0f];
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.text = @"谨遵中基协《私募投资基金募集行为管理办法》之规定，上海银来股权投资基金有限公司只对“具备相应风险识别能力和风险承担能力投资于单只私募基金的金额不低于100万元，且个人金融类资产不低于300万元或者最近三年个人年均收入不低于50万元人民币”的特定合格投资者进行私募投资基金产品的相关宣传推介服务。您需要进行身份认证后才能访问。";
    [self addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(baseView).mas_offset(20);
        make.right.mas_equalTo(baseView).mas_offset(-20);
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(30);
    }];
    
    
    UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sureButton addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchUpInside];
    sureButton.backgroundColor = YLLOrgColor;
    [sureButton setTitle:@"确 认 符 合" forState:UIControlStateNormal];
    [self addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(contentLabel).mas_offset(10);
        make.right.mas_equalTo(contentLabel).mas_offset(-10);
        make.top.mas_equalTo(contentLabel.mas_bottom).mas_offset(40);
        make.bottom.mas_equalTo(baseView).mas_offset(-25);
        make.height.mas_equalTo(40);
    }];
    
    sureButton.layer.masksToBounds = YES;
    sureButton.layer.cornerRadius = 20;

    
}

- (void)sure
{
    NSString *url = [NSString stringWithFormat:@"%@Product/SetFundQualifications", YLURL];
    
    [[WHNetworkTool shareInstance] sendPostWithUrl:url header:[YLAccountTool header] params:@{@"Status" : @(1)} success:^(id responseObject) {
        
    } fail:^(NSError *error) {
        
    }];
    
    YLAccount *account = [YLAccountTool account];
    account.fundQualifications = YES;
    [YLAccountTool saveAccount:account];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(qualificationSureViewSure:)]) {
        [self.delegate qualificationSureViewSure:self];
    }
   
    
}
@end
